package com.yinhai.model.tree;

import java.util.List;

import com.yinhai.model.ContactGroup;
import com.yinhai.model.ContactsUser;
import com.yinhai.model.UserUserContact;

public final class InitManagerData {
	
	public static UserUserContact GroupToUserUser(ContactGroup obj) {
		UserUserContact contact = new UserUserContact();
		contact.setId(obj.getGroupId());
		contact.setName(obj.getName());
		contact.setNum(obj.getPeopleNume() + "");
		//代码中用的是变量，为了测试方便直接写死值在这个地方
		contact.setType("3");//Contact.CONTACT_TYPE_GROU;//1本地通讯录，2集团通讯录数据,3分组数据
		contact.setParent_id(obj.getParent_id());
		contact.setFullpysep(obj.getFullpysep());
		return contact;
	}
	
	public static UserUserContact UserToUserUser(ContactsUser obj) {
		UserUserContact contact = new UserUserContact();
		contact.setId(obj.getUserid());
		//代码中用的是变量，为了测试方便直接写死值在这个地方
		// LOCAL_CONTACT_GROUP_ID='groupId';//本地通讯录组所对应的ID
		if (!obj.getGroupId()
				.equals("groupId")) {
			contact.setName(obj.getName() + '('
					+ obj.getGroupName() + ')');
		} else {
			contact.setName(obj.getName());
		}
		contact.setPhone(obj.getTelPhone());
		contact.setType(contact.getType());
		contact.setParent_id(obj.getGroupId());
		contact.setFullpysep(obj.getFullpysep());
		return contact;
	}
	
	public static void InitAllManagerData(List<ContactsUser> userList, List<ContactGroup> groupList) {
		IndexCodeTreeManager ictm = IndexCodeTreeManager.GetInstance();
		GroupSearchTreeManager gstm = GroupSearchTreeManager.GetInstance();
		
		if(userList != null) {
			for(ContactsUser userData : userList) {
				UserUserContact uuc = UserToUserUser(userData);

				if(userData.getTelPhone() != null) {
					ictm.map.put(userData.getTelPhone() + '#', userData);
					gstm.map.put(userData.getTelPhone() + '#', uuc);
				}
				if(userData.getShortNum() != null && userData.getShortNum().length() >= 4) {
					ictm.map.put(userData.getShortNum() + '%', userData);
					gstm.map.put(userData.getShortNum() + '%', uuc);
				}
				if(userData.getNameSimple() != null) {
					ictm.map.put(userData.getNameSimple() + '&', userData);
				}
				if(userData.getFullpynum() != null) {
					ictm.map.put(userData.getFullpynum() + '*', userData);
				}
				if(userData.getFirstpy() != null) {
					gstm.map.put(userData.getFirstpy() + '&', uuc);
				}
				if(userData.getFullpy() != null) {
					gstm.map.put(userData.getFullpy() + '*', uuc);
				}
			}
			
			for(ContactGroup groupData : groupList) {
				UserUserContact uuc = GroupToUserUser(groupData);
				
				if(groupData.getName() != null) {
					gstm.map.put(groupData.getName() + '+', uuc);
				}
				if(groupData.getPy() != null) {
					gstm.map.put(groupData.getPy() + '<', uuc);
				}
				if(groupData.getFullPY() != null) {
					gstm.map.put(groupData.getFullPY() + '>', uuc);
				}
			}
		}
	}
}
